<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<link rel="stylesheet" type="text/css" href="../../src/css/reset.css" />
		<link rel="stylesheet" type="text/css" href="../../src/css/main.css" />
		<link rel="stylesheet" type="text/css" href="../../libs/leaflet/leaflet.css" />
		<script src="../../libs/leaflet/leaflet.js" type="text/javascript" charset="utf-8"></script>
		<script src="../../libs/leaflet/leaflet.ChineseTmsProviders.js" type="text/javascript" charset="utf-8"></script>
	</head>
	<body>
		<div id="map"></div>
		<script type="text/javascript"  id="my_script">
			let map = L.map('map', {
				center: [32.444721222054795, 119.4224873962402], // leaflet 所有坐标都是纬度在前,经度在后的
				zoom: 14
			})

			// 地图依赖于leaflet.ChineseTmsProviders.js  他提供4326坐标系的天地图,高德地图等
			let baseLayer = L.tileLayer.chinaProvider('TianDiTu.Normal.Map', {
				maxZoom: 18,
				minZoom: 10
			})
			map.addLayer(baseLayer)
			let labelLayer = L.tileLayer.chinaProvider('TianDiTu.Normal.Annotion', {
				maxZoom: 18,
				minZoom: 10
			})
			map.addLayer(labelLayer)
			
			L.marker([32.444721222054795, 119.4224873962402], {
				draggable: true
			}).addTo(map)

			let points = [
				[32.43, 119.42],
				[32.44, 119.42],
				[32.45, 119.42],
				[32.46, 119.42],
				[32.47, 119.42]
			]
			let polyline = L.polyline(points, {
				color: '#f00'
			}).addTo(map)
			let markers = []
			points.map((item, index) => {
				let marker = L.circleMarker(item, {
					radius: 6,
					color: '#E8542B',
					fillColor: '#fff',
					fillOpacity: 1
				}).addTo(map)
				markers.push(marker)
			})
			markers.map(item=>{
				item.on("mousedown", mousedown)
			})
			function mousedown() {
				map.dragging.disable()
				this.remove()
				let index = markers.indexOf(this)
				let _marker = null
				map.on("mousemove", (param) => {
					let latlng = param.latlng
					if (_marker) {
						_marker.remove()
					}
					_marker = L.circleMarker(latlng, {
						radius: 6,
						color: '#E8542B',
						fillColor: '#fff',
						fillOpacity: 1
					}).addTo(map)
					points[index] = [latlng.lat, latlng.lng]
					markers[index] = _marker
					markers.map(item=>{
						item.on("mousedown", mousedown)
					})
					polyline.setLatLngs(points)
				})
				map.on("mouseup", () => {
					map.off("mousemove")
					map.dragging.enable()
				})
			}
		</script>
	</body>
</html>
